<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-inline' 'self'; media-src 'self' data:;">
    <title>indexdb测试</title>
    <script>
        // 打开或创建一个数据库
        var request = indexedDB.open('boot', 1); // 修复：使用具体版本号
        console.log("request:",request);

        // 处理数据库升级
        request.onupgradeneeded = function (event) {
            console.log("onupgradeneeded event:",event);
            var db = event.target.result;

            // 创建对象存储（表）并设置主键
            var objectStore = db.createObjectStore('meetinglog', { keyPath: 'id' });

            // 创建索引
            objectStore.createIndex('username', 'id', { unique: false });
        };

        // 数据库打开成功时的回调
        request.onsuccess = function (event) {
            console.log("request.onsuccess event:",event);
            var db = event.target.result;

            // 进行事务操作
            var transaction = db.transaction('meetinglog', 'readwrite');
            var objectStore = transaction.objectStore('meetinglog');

            // 插入数据
            objectStore.add({ id: 1, username: '李四', text: "我提议：2025年12月设立健康事业部，由张三担任执行官。" });
            objectStore.add({ id: 2, username: '张三', text: "我附议。" });

            // 查询数据
            var query = objectStore.get(1);
            query.onsuccess = function (event) {
                console.log("query.onsuccess event:",event);
                console.log(event.target.result);
            };
        };

        // 错误处理
        request.onerror = function (event) {
            console.log("onerror event:",event);
            console.error('Database error:', event.target.error);
        };
    </script>
</head>
<body>
    <h1>这是一个标题</h1>
    <p>这是一个段落。</p>
</body>
</html>